<template>
  <div id="app">
    <router-view />
    <theme-picker />
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";

export default {
  name: "App",
  components: { ThemePicker },
  metaInfo() {
    return {
      title:
        this.$store.state.settings.dynamicTitle &&
        this.$store.state.settings.title,
      titleTemplate: (title) => {
        return title
          ? `${title} - ${process.env.VUE_APP_TITLE}`
          : process.env.VUE_APP_TITLE;
      },
    };
  },
  computed: {
    sideTheme() {
      return this.$store.state.settings.sideTheme;
    },
  },
  watch: {
    sideTheme(newVal) {
      if (newVal === "theme-dark") {
        this.$el.classList.add("dark");
      } else {
        this.$el.classList.remove("dark");
      }
    },
  },
  moundted() {
    const sideTheme = this.$store.state.settings.sideTheme;
    if (sideTheme === "theme-dark" && !sideTheme.classList.contains("dark")) {
      this.$el.classList.add("dark");
      window.document.body.classList.add("dark");
    }
  },
};
</script>
<style scoped>
#app .theme-picker {
  display: none;
}
</style>
